/**
 * Copyright (c) 2009 Jim Hurne
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package org.tzconverter.main;

import org.tzconverter.AppPrefs;
import org.tzconverter.opacity.level.OpacityLevelModel;

/**
 * Default implementation of the MainModel.  This model also implements
 * the OpacityLevelModel interface, which allows it to be used as the model
 * component of both the Main triad and the Opacity Level triad.  Thus,
 * the two triads "communicate", but avoids the need for a coordinator.
 * 
 * @author Jim Hurne
 * @since Jun 24, 2009
 */
public class DefaultMainModel implements MainModel, OpacityLevelModel
{
  private final AppPrefs prefs;
  
  private boolean alwaysOnTop;
  private boolean translucent;
  private float opacityLevel;
  
  /**
   * @param prefs
   */
  public DefaultMainModel(AppPrefs prefs)
  {
    this.prefs = prefs;
  }

  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#isAlwaysOnTop()
   */
  public boolean isAlwaysOnTop()
  {
    return alwaysOnTop;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#setAlwaysOnTop(boolean)
   */
  public void setAlwaysOnTop(boolean alwaysOnTop)
  {
    this.alwaysOnTop = alwaysOnTop;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#isTranslucent()
   */
  public boolean isTranslucent()
  {
    return translucent;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#setTranslucent(boolean)
   */
  public void setTranslucent(boolean translucent)
  {
    this.translucent = translucent;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#getOpacityLevel()
   */
  public float getOpacityLevel()
  {
    return opacityLevel;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#setOpacityLevel(float)
   */
  public void setOpacityLevel(float opacityLevel)
  {
    this.opacityLevel = opacityLevel;
  }

  public void loadSettings()
  {
    alwaysOnTop = prefs.isAlwaysOnTop();
    translucent = prefs.isTranslucent();
    opacityLevel = prefs.getOpacityLevel();
  }
  
  public void loadDefaultSettings()
  {
    alwaysOnTop = AppPrefs.DEFAULT_ALWAYS_ON_TOP;
    translucent = AppPrefs.DEFAULT_ALWAYS_ON_TOP;
    opacityLevel = AppPrefs.DEFAULT_OPACITY_LEVEL;
  }
  
  /* (non-Javadoc)
   * @see org.tzconverter.main.MainModel#saveSettings()
   */
  public void saveSettings()
  {
    prefs.setAlwaysOnTop(alwaysOnTop);
    prefs.setTranslucent(translucent);
    prefs.setOpacityLevel(opacityLevel);
  }
}
